//
//  HBStatusModel.swift
//  sinaWeibo
//
//  Created by Beans on 16/6/26.
//  Copyright © 2016年 iceWorks. All rights reserved.
//

import UIKit

class HBStatusModel: NSObject {

    /// created_at	string	微博创建时间
    var created_at: String?
    /// id	int64	微博ID
    var id: Int = 0
    /// text	string	微博信息内容
    var text: String?
    /// source	string	微博来源
    var source: String?

    /// reposts_count	int	转发数
    var reposts_count: Int = 0
    /// comments_count	int	评论数
    var comments_count: Int = 0
    /// attitudes_count	int	表态数
    var attitudes_count: Int = 0

    /// user	object	微博作者的用户信息字段 详细
    var user: HBStatusUserModel?
    /// retweeted_status	object	被转发的原微博信息字段，当该微博为转发微博时返回 详细
    var retweeted_status: HBStatusModel?

    /// pic_urls 
    var pic_urls: [HBStatusPicViewModel]?       // 为什么是viewModel

    init(dic: [String:AnyObject]) {
        super.init()

        setValuesForKeysWithDictionary(dic)

        // 判断user里数据不为空
        if let userDic = dic["user"] as? [String:AnyObject] {
            self.user = HBStatusUserModel(dict: userDic)
        }

        // 转发微博
        if let retweetDic = dic["retweeted_status"] as? [String:AnyObject] {
            retweeted_status = HBStatusModel(dic: retweetDic);
        }

        // 微博图片
        if let picUrlsArr = dic["pic_urls"] as? [[String: AnyObject]] {
            // 初始化属性数组
            pic_urls = [HBStatusPicViewModel]()
            // 遍历数组, 字典转模型
            for picUrlDict in picUrlsArr {
                let model = HBStatusPicModel(dictionary: picUrlDict)
                let viewModel = HBStatusPicViewModel(model: model)
                // 添加到数组
                pic_urls?.append(viewModel)
            }
        }
    }

    override func setValue(value: AnyObject?, forUndefinedKey key: String) {
    }

}
